import request from '@/utils/request'

// 顶部添加常量定义
const DocServer = 'http://localhost:888/';
export { DocServer };  // 添加具名导出

// 修改下载逻辑
export function downloadFile(filePath) {
  window.location.href = DocServer + filePath;
}

// 查询课程文件列表
export function listDocument(query) {
  return request({
    url: '/course/document/list',
    method: 'get',
    params: query
  })
}

// 查询课程文件详细
export function getDocument(recordId) {
  return request({
    url: '/course/document/' + recordId,
    method: 'get'
  })
}

// 新增课程文件
export function addDocument(data) {
  return request({
    url: '/course/document',
    method: 'post',
    data: data
  })
}

// 修改课程文件
export function updateDocument(data) {
  return request({
    url: '/course/document',
    method: 'put',
    data: data
  })
}

// 删除课程文件
export function delDocument(recordId) {
  return request({
    url: '/course/document/' + recordId,
    method: 'delete'
  })
}

// 根据课程ID查询课程信息
export function getDocumentsByCourseId(courseId) {
  return request({
    url: '/course/document/course/' + courseId,
    method: 'get'
  })
}